/**
 * 
 */
package by.imotaeva.printing_services.services.impl;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import by.imotaeva.printing_services.dataaccess.CarboardDao;
import by.imotaeva.printing_services.datamodel.Carboard;
import by.imotaeva.printing_services.services.CarboardService;

/**
 * @author Inna
 *
 */

@Service
public class CarboardServiceImpl implements CarboardService{
	private static final Logger LOGGER = LoggerFactory.getLogger(CarboardServiceImpl.class);

	@Inject
	private CarboardDao dao;

	@PostConstruct
	private void init() {
		// this method will be called by Spring after bean instantiation. Can be
		// used for any initialization process.
		LOGGER.info("Instance of CarboardService is created. Class is: {}", getClass().getName());
	}

	@Override
	public Carboard get(Long id) {
		Carboard entity = dao.getById(id);
		return entity;
	}

	@Override
	public void saveOrUpdate(Carboard carboard) {
		if (carboard.getId() == null) {
			LOGGER.debug("Save new: {}", carboard);
			dao.insert(carboard);
		} else {
			LOGGER.debug("Update: {}", carboard);
			dao.update(carboard);
		}     
	}

	@Override
	public void delete(Carboard carboard) {
		LOGGER.debug("Remove: {}", carboard);
		dao.delete(carboard.getId());
	}

	@Override
	public void deleteAll() {
		LOGGER.debug("Remove all carboards");
		dao.deleteAll();
	}


}
